package gruppe7.servlets;

import gruppe7.util.Html;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ContactSendMail extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private Html htmlInclude = new Html();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        RequestDispatcher rd = request.getRequestDispatcher("main_links.jsp");
        HttpSession currentSession = request.getSession();

        out.println(htmlInclude.setHeader("Login"));
        out.println("<div id ='header'></div>");
        out.println("<div id='nav-container'>");
        out.println("<div id='top-links'>");
        rd.include(request, response);

        out.println("<div id='login'>");
        String myname = (String) currentSession.getAttribute("username");

        if (myname != null) {
            out.println("<p class='blue'>[ You're logged in as " + myname + " - <a href='Logout'>logout?</a> ]</p>");
        } else {
            out.println("<p class='blue'>[ You're not logged in ]</p>");
        }

        out.println("</div>");

        out.println("</div></div><div id ='content'>");
        out.println("<div id='content-left'>");

        out.println("<p>This function do not work right now!</p>");
        out.println("</div></div>");
        out.println(htmlInclude.setFooter());
    }
}
